package com.lin.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharePreferenceUtil {

	static SharePreferenceUtil mSharePreferenceUtil;
	public static SharePreferenceUtil getInstance() {
		if(mSharePreferenceUtil == null) {
			mSharePreferenceUtil = new SharePreferenceUtil();
		}
		return mSharePreferenceUtil;
	}


	public boolean updateUserInfo(Context mContext, String userName, String password) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		Editor editor = mSharedPreferences.edit();
		editor.putString("username", userName);
		editor.putString("password", password);
		return editor.commit();
	}

	
	public boolean saveUserInfo(Context mContext, String UserInfo) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		Editor editor = mSharedPreferences.edit();
		editor.putString("userinfo", UserInfo);
		return editor.commit();
	}

	public boolean deleteUserInfo(Context mContext) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		Editor editor = mSharedPreferences.edit();
		editor.putString("userinfo", "");
		return editor.commit();
	}
	
	public String getUserInfo(Context mContext) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		String userinfo = mSharedPreferences.getString("userinfo", "");
		return userinfo;
	}
	
	public boolean updateUserInfo(Context mContext, String uid, String userName, String password, String nickName) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		Editor editor = mSharedPreferences.edit();
		editor.putString("uid", uid);
		editor.putString("username", userName);
		editor.putString("password", password);
		editor.putString("nickName", nickName);
		return editor.commit();
	}


	public boolean updateLastInsertedIdOfMap(Context mContext, String id, String gid) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		Editor editor = mSharedPreferences.edit();
		editor.putString("lastinsertedid" + gid, id);
		return editor.commit();
	}

	public String getLastInsertedId(Context mContext, String gid) {
		try {

			SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
			String id = mSharedPreferences.getString("lastinsertedid" + gid, "");
			return id;
		} catch(NullPointerException e) {
			e.printStackTrace();
			return "12";
		}
	}


	public String getUserId(Context mContext) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		String uid = mSharedPreferences.getString("uid", "");
		return uid;
	}


	public String getUserName(Context mContext) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		String username = mSharedPreferences.getString("username", "");
		return username;
	}

	public String getPassword(Context mContext) {
		SharedPreferences mSharedPreferences = mContext.getSharedPreferences("woniu", 3);
		String username = mSharedPreferences.getString("password", "");
		return username;
	}


}